/**
    Copyright (c) 2011 ATTi 
    All rights reserved.
    Author: Michael Shu
    Date: 11/14/2011
*/

trigger FulfillmentItemUpdateIOGCases on Fullfilment_Item__c (after update) {
    if(trigger.isAfter){
        if(trigger.isUpdate){
            Map<ID, Fullfilment_Item__c> fis = new Map<ID, Fullfilment_Item__c>();
            for(Fullfilment_Item__c FI : trigger.new){
                Fullfilment_Item__c oldf = trigger.oldMap.get(FI.Id);
                if((FI.status__c != oldf.status__c && CaseIOGClass.FI_END_STATUS.contains(FI.status__c))    
                   || FI.OwnerId != oldf.OwnerId || FI.Current_Step__c != oldf.Current_Step__c 
                   || FI.Fulfillment_Product_Group__c != oldf.Fulfillment_Product_Group__c || (FI.Escalated__c && !oldf.Escalated__c)
                   || FI.RootProcessId__c != oldf.RootProcessId__c){
                    fis.put(FI.Id, FI);
                }
            }
            if(!fis.isEmpty()){
                CaseIOGClass.updateCaseFromFulfillmentItem(fis, null);
            }
        }
    }
}